<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>微信会员管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		
		function replyToUser(id){
			var replyContent = $('#reply_content_'+id).val();
			var params = {'id':id,'replyContent':replyContent};
			$.post('${ctx}/wechat/wechatMember/reply',params,function(data){
				if(data['success'] == 'false'){
					alert("发送失败");
				}
			});
		}
		
		function open(memberId){
			top.$.jBox.open("iframe:${ctx}/wechat/wechatMember/recommendMemberList?isFind=no&memberId="+memberId, 
					"设置推荐人",$(top.document).width()-500,$(top.document).height()-1200,{
				buttons:{"关闭":true}, loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
				}
			});
		}
		
		function sendCart(id){
			if(confirm('确认要赠送会卡吗？')){
				$.getJSON("${ctx}/huisimeng/memberCartLog/sendCart",{id:id}, function(data){
	                alert(data.message);
				});
			}
		}
		
		function sync(id){
			
			$.getJSON("${ctx}/wechat/wechatMember/syncFromWechatMember",{id:id}, function(data){
	            alert(data.message);
	        });
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/wechat/wechatMember/">微信会员列表</a></li>
		<%-- <shiro:hasPermission name="sys:user:edit"><li><a href="${ctx}/wechat/wechatMember/form">微信会员添加</a></li></shiro:hasPermission> --%>
	</ul>
	<form:form id="searchForm" modelAttribute="wechatMember" action="${ctx}/wechat/wechatMember/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		
		<%-- <shiro:hasPermission name="sys:user:edit"><label>商家 ：</label><form:input path="user.name" htmlEscape="false" maxlength="50" class="input-medium"/></shiro:hasPermission> --%>
		<label>会员ID ：</label><form:input path="id" htmlEscape="false" maxlength="50" class="input-medium"/>
		<label>姓名 ：</label><form:input path="name" htmlEscape="false" maxlength="50" class="input-medium"/>
		<label>手机 ：</label><form:input path="mobile" htmlEscape="false" maxlength="50" class="input-medium"/>
		<label class="control-label" style="margin-top:3px;">开始时间:</label>
					<script src="${ctxStatic}/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
					<input id="createTime" name="startTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
						value="<fmt:formatDate value="${wechatMember.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
						onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>  
<label class="control-label" style="margin-top:3px;">结束时间:</label>
					<input id="endTime" name="endTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
						value="<fmt:formatDate value="${wechatMember.endTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
						onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
		
		
		&nbsp;<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
		&nbsp;<a  href="${ctx}/wechat/wechatMember?zhuce=1" class="btn btn-primary" type="button" >已注册会员</a>
	</form:form>
	
	
<div style="overflow:scroll;">
	<tags:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered ">
		<thead><tr>
		<%-- <shiro:hasPermission name="sys:user:edit"><th>所属商家</th></shiro:hasPermission> --%>
		<th>ID</th>
		<th>姓名</th>
		<th>昵称</th>
		<th>会员卡号</th>
		<th>手机号</th>
		<th>总积分</th>
		<th>活动积分</th>
		<th>消费积分</th>
		<!-- <th>充值信用积分（元）</th>
		<th>押金信用积分（元）</th> -->
		<th>最后签到时间</th><th>注册时间</th><shiro:hasPermission name="wechat:wechatMember:edit"><th>操作</th></shiro:hasPermission></tr></thead>
		<tbody>
		<c:forEach items="${page.list}" var="wechatMember">
			<tr>
				<%-- <shiro:hasPermission name="sys:user:edit"><td>${wechatMember.user.name}</td></shiro:hasPermission> --%>
				<td>${wechatMember.id}</td>
				<td><a title="${wechatMember.name}" style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;width: 80px;display: inline-block;" href="${ctx}/wechat/wechatMember/form?id=${wechatMember.id}">${wechatMember.name }</a></td>
				<td><span title="${wechatMember.nickname }" style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;width: 80px;display: inline-block;">${wechatMember.nickname }</span></td>
				<td>${wechatMember.number}</td>
				<td>${wechatMember.mobile}</td>
				<td>
					<c:if test="${wechatMember.score eq null}">0</c:if>
		          	<c:if test="${wechatMember.score ne null}">
		          		<c:if test="${wechatMember.score eq 0}">0</c:if>
		          		<c:if test="${wechatMember.score ne 0}">
		          			${wechatMember.score}
		          		</c:if>
		          	</c:if>
				</td>
				<td>
					<c:if test="${wechatMember.recommendScore eq null}">0</c:if>
		          	<c:if test="${wechatMember.recommendScore ne null}">
		          		<c:if test="${wechatMember.recommendScore eq 0}">0</c:if>
		          		<c:if test="${wechatMember.recommendScore ne 0}">
		          			${wechatMember.recommendScore}
		          		</c:if>
		          	</c:if>
					
				</td>
				<td>
					<c:if test="${wechatMember.consumeScore eq null}">0</c:if>
		          	<c:if test="${wechatMember.consumeScore ne null}">
		          		<c:if test="${wechatMember.consumeScore eq 0}">0</c:if>
		          		<c:if test="${wechatMember.consumeScore ne 0}">
		          			${wechatMember.consumeScore}
		          		</c:if>
		          	</c:if>
				</td>
				<%-- <td>
					<c:if test="${wechatMember.creditScore eq null}">0</c:if>
		          	<c:if test="${wechatMember.creditScore ne null}">
		          		<c:if test="${wechatMember.creditScore eq 0}">0</c:if>
		          		<c:if test="${wechatMember.creditScore ne 0}">
				       		<fmt:formatNumber value="${wechatMember.creditScore/1000 }" pattern="#,###.###"  minFractionDigits="3"/>
		          		</c:if>
		          	</c:if>
					
				</td>
				<td>
					<c:if test="${wechatMember.unusable eq null}">0</c:if>
		          	<c:if test="${wechatMember.unusable ne null}">
		          		<c:if test="${wechatMember.unusable eq 0}">0</c:if>
		          		<c:if test="${wechatMember.unusable ne 0}">
				       		<fmt:formatNumber value="${wechatMember.unusable/1000 }" pattern="#,###.###"  minFractionDigits="3"/>
		          		</c:if>
		          	</c:if>
					
				</td> --%>
				<td>${wechatMember.lastSignTime}</td>
				<td><div style="width: 120px;"><fmt:formatDate value="${wechatMember.createTime}" type="both"/></div></td>
				<shiro:hasPermission name="wechat:wechatMember:edit"><td>

					<div class="btn-toolbar" style="margin: 0;width: 400px;">
						<div class="btn-group">
							 <button class="btn btn-warning">编辑</button>
							  <button class="btn btn-warning dropdown-toggle" data-toggle="dropdown">
							    <span class="caret"></span>
							  </button>
							  <ul class="dropdown-menu">
							  	<li><a href="${ctx}/wechat/wechatMember/form?id=${wechatMember.id}">修改</a></li>
							  <%-- 	<li><a href="${ctx}/wechat/wechatMember/delete?id=${wechatMember.id}" onclick="return confirmx('确认要删除该微信会员吗？', this.href)">删除</a></li> --%>
							  	<li><a href="${ctx}/wechat/wechatMember/remove?id=${wechatMember.id}" onclick="return confirmx('确认要删除该微信会员吗？', this.href)">彻底删除</a></li>
							  	<li><a href="##" onclick="sync(${wechatMember.id})">拉取</a></li>
							  	<li class="divider"></li>
							  	<li>
									<%-- <c:if test="${wechatMember.isAdmin eq '0' or empty wechatMember.isAdmin }"><a href="${ctx}/wechat/wechatMember/updateMemberByAdmin?isAdmin=1&memberId=${wechatMember.id}">设为管理员</a></c:if>
									<c:if test="${wechatMember.isAdmin eq '1' }"><a href="${ctx}/wechat/wechatMember/updateMemberByAdmin?isAdmin=0&memberId=${wechatMember.id}">取消管理员</a></c:if>
								 --%>
								 <li><a href="##" onclick="sendCart(${wechatMember.id})">赠送会员卡</a></li>
								 
								</li>
							  </ul>
						</div>
						
						<div class="btn-group">
							<button class="btn btn-danger">消息</button>
							<button class="btn btn-danger dropdown-toggle" data-toggle="dropdown">
						  		<span class="caret"></span>
							</button>
							 <ul class="dropdown-menu">
							 	<li><c:if test="${user.interfaceFlag==true}"><a data-target="#myModal_1" data-toggle="modal" style="cursor:pointer">回复</a></c:if></li>
							 	<li><a href="${ctx}/wechat/massMedia/sendNewsform?id=${wechatMember.id}" >发送图文信息</a></li>
							 </ul>
						</div>
						
						<div class="btn-group">
							<button class="btn btn-success">积分</button>
							<button class="btn btn-success dropdown-toggle" data-toggle="dropdown">
						    	<span class="caret"></span>
							</button>
							<ul class="dropdown-menu">
								<li><a href="${ctx}/wechat/memberScore?wechatMember.id=${wechatMember.id}">积分记录</a></li>
								<li>
									<shiro:hasPermission name="sys:user:edit">
										<a href="${ctx}/wechat/wechatMember/cform?id=${wechatMember.id}">充值积分</a>
									</shiro:hasPermission>
								</li>
								<li class="divider"></li>
								<li><a href="${ctx}/wechat/wechatMember/myRecommend?id=${wechatMember.id}" >查看推荐会员</a></li>
							</ul>
						</div>
						
						<div class="btn-group">
							<%-- <button onclick="open(${wechatMember.id})" class="btn btn-success">设置上级推荐人</button> --%>
							<%-- <a href="javascript:open(${wechatMember.id})" class="btn btn-success" >设置上级推荐人</a> --%>
						</div>
					</div>
					
					<!-- 回复内容 -->
						<div id="myModal_1" class="modal hide fade" tabindex="-1" style="width:300px" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
								<h3 id="myModalLabel">回复留言</h3>
							</div>
							<div class="modal-body">
								<textarea name="reply" id="reply_content_${wechatMember.id }" rows="5" cols="20"></textarea>
							</div>
							<div class="modal-footer">
								<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
								<button class="btn btn-primary"  data-dismiss="modal" aria-hidden="true" onclick="replyToUser('${wechatMember.id }');">回复</button>
							</div>
						</div> <!-- 回复内容 结束-->
					
				</td></shiro:hasPermission>
			</tr>
		</c:forEach>
		</tbody>
	</table>
</div>		
	<div class="pagination">${page}</div>
</body>
</html>
